package com.cyys.common.dataScope;

import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * @author cyys
 * @date 2020/4/26
 */
public class SelectListByScope extends AbstractMethod {

	public SelectListByScope() {
		super("selectListByScope");
	}

	@Override
	public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
		SqlMethod sqlMethod = SqlMethod.SELECT_LIST;
		String sql = String.format(sqlMethod.getSql(), this.sqlFirst(), this.sqlSelectColumns(tableInfo, true),
				tableInfo.getTableName(), this.sqlWhereEntityWrapper(true, tableInfo), this.sqlOrderBy(tableInfo),
				this.sqlComment());
		SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sql, modelClass);
		return this.addSelectMappedStatementForTable(mapperClass, sqlSource, tableInfo);
	}

//	@Override
//	public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
//		SqlMethod sqlMethod = SqlMethod.SELECT_LIST;
//		String sql = String.format(sqlMethod.getSql(), sqlFirst(), sqlSelectColumns(tableInfo, true),
//				tableInfo.getTableName(), sqlWhereEntityWrapper(true, tableInfo), sqlComment());
//		SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
//		return this.addSelectMappedStatementForTable(mapperClass, "selectListByScope", sqlSource, tableInfo);
//	}

}
